﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mail;
using System.Net.Mail;

namespace Acaweb.Servicios.Utility
{
    public static class FactoryEmail
    {
        public static bool EnviarMail(string De, string Password, List<string> Para, string Mensaje, string Asunto)
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            Para.ForEach(t => msg.To.Add(t));
            msg.From = new System.Net.Mail.MailAddress(De, "Tu Nombre", System.Text.Encoding.UTF8);
            msg.Subject = Asunto;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
            msg.Body = Mensaje;
            msg.BodyEncoding = System.Text.Encoding.UTF8;
            msg.IsBodyHtml = false;

            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential(De, Password);
            client.Port = 587;
            client.Host = "smtp.gmail.com"; //Cambiar Host
            client.EnableSsl = true;
            try
            {
                client.Send(msg);
                return true;
            }
            catch (System.Net.Mail.SmtpException)
            {
                return false;
            }

        }
    }
}